/**
 * Created with JetBrains PhpStorm.
 * User: vander
 * Date: 5/26/13
 * Time: 11:46 PM
 * To change this template use File | Settings | File Templates.
 */
var Store = Class.create({
   initialize: function(){
       this.books = new Array();
   },
   load: function(o){
       //o --> collections json object
       var _this = this;
       this.books.clear();
       $j.each(o.books, function(index, value){
           var bookInfo = new Object();

           $j.each(value, function(key, val){
               bookInfo[key] = val;
           });

           _this.books.push(bookInfo);
       });

       $j("#" + Static.storeList).empty();

       $j.each(_this.books, function(index, value){
           var liTag = new Element("li", {bookId: value.bookId});
           var img = $j("<img>").attr('src', Static.serverPath + value.resourcesPath + value.coverImage).attr({width: "80", height: "80"});
           var aTag = $j("<a></a>").append(img).append(value.name);
//               var splitaTag = $j("<a href='#popss' data-rel='popup'>Setting</a>");

           $j(aTag).on("tap", function(){
                if(!Global.collections.isInCollections(value.bookId)){
                    Global.downloading.add(value);
                    $j.mobile.changePage("#downloading");
                }
           });

           $j(liTag).append(aTag).appendTo("#" + Static.storeList);
       });

       $j("#" + Static.storeList).listview("refresh");
   }
});